<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>搜索结果</title>
</head>
<body>

<div class="container-xl">
    <div class="card">
        <div class="card-header">
            <h3 class="card-title" id="search-title">搜索结果</h3>
        </div>
        <div class="card-body" id="search-results">
            <!-- 搜索结果将在这里动态显示 -->
        </div>
    </div>
</div>

<script>
    $(function() {
        // 监听搜索完成事件
        $('#bit-forum-content').on('searchComplete', function(event, searchData, searchTitle) {
            // 更新搜索标题
            $('#search-title').text(`"${searchTitle}" 的搜索结果`);

            if (searchData && searchData.length > 0) {
                // 有搜索结果，构建文章列表
                let resultHtml = '<div class="list-group list-group-flush">';
                searchData.forEach(article => {
                    resultHtml += `
                    <div class="list-group-item">
                        <div class="row align-items-center">
                            <div class="col">
                                <a href="javascript:void(0);" onclick="loadArticleDetail(${article.id})" class="text-reset d-block">
                                    ${article.title}
                                </a>
                                <div class="text-muted mt-1">
                                    <span>作者: ${article.user.nickname}</span>
                                    <span class="ms-2">发布时间: ${formatDate(article.createTime)}</span>
                                </div>
                            </div>
                        </div>
                    </div>
                `;
                });
                resultHtml += '</div>';
                $('#search-results').html(resultHtml);
            } else {
                // 无搜索结果
                $('#search-results').html(`
                <div class="text-center p-4">
                    <h3 class="mb-3">未找到相关文章</h3>
                    <div class="text-muted">您搜索的关键词"${searchTitle}"暂无相关结果</div>
                </div>
            `);
            }
        });

        // 格式化日期的辅助函数
        function formatDate(dateStr) {
            return new Date(dateStr).toLocaleDateString('zh-CN', {
                year: 'numeric',
                month: '2-digit',
                day: '2-digit',
                hour: '2-digit',
                minute: '2-digit'
            });
        }
    });

    // 添加加载文章详情的函数
    function loadArticleDetail(articleId) {
        // 设置当前文章ID
        currentArticle = {
            id: articleId
        };

        // 加载详情页面
        $('#bit-forum-content').load('details.html');
    }
</script>

</body>
</html>